package com.base.cn.platform.os.controller.classes.task;

import com.base.cn.platform.os.common.controller.BaseController;
import com.base.cn.platform.os.entity.classes.task.ClassesTaskData;
import com.base.cn.platform.os.entity.classes.task.ClassesTaskDataCondition;
import com.base.cn.platform.os.service.classes.task.ClassesTaskDataBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

/**
 * 作业数据Controller
 *
 * @author s.li
 * @date 2018/12/24
 */
@RestController
@RequestMapping("/course")
public class ClassesTaskDataController extends BaseController {

    @Autowired
    private ClassesTaskDataBiz classesTaskDataBiz;

    /**
     * 保存作业数据
     * @param examId 作业ID
     * @param status 状态
     * @param subjectIds 作业专业ID串
     * @param courseIds 课程ID串
     * @param classesIds 班级ID串
     */
    @RequestMapping("/saveClassesTaskData")
    public void saveClassesTaskData(@RequestParam("examId") BigDecimal examId,
                                    @RequestParam("status") int status,
                                    @RequestParam("subjectIds") String subjectIds,
                                    @RequestParam(value = "courseIds",required = false) String courseIds,
                                    @RequestParam(value = "classesIds",required = false) String classesIds){
        ClassesTaskData classesTaskData = new ClassesTaskData();
        classesTaskData.setExamId(examId);
        classesTaskData.setStatus(status);
        classesTaskData.setSubjectIds(subjectIds);
        classesTaskData.setCourseIds(courseIds);
        classesTaskData.setClassesIds(classesIds);
        classesTaskDataBiz.saveClassesTaskData(classesTaskData);
    }

    /**
     * 删除作业数据
     * @param examIds 作业ID串
     */
    @RequestMapping("/deleteClassesTaskDataByIds")
    public void deleteClassesTaskDataByIds(@RequestParam("examIds") String examIds){
        classesTaskDataBiz.deleteClassesTaskDataByIds(examIds);
    }

    /**
     * 修改作业状态
     * @param examIds 作业ID
     * @param status 状态
     */
    @RequestMapping("/updateClassesTaskDataStatus")
    public void updateClassesTaskDataStatus(@RequestParam("examIds") String examIds,
                                            @RequestParam("status") int status){
        ClassesTaskData classesTaskData = new ClassesTaskData();
        classesTaskData.setStatus(status);
        classesTaskDataBiz.updateByWhereSql(classesTaskData," examId in ("+examIds+")");
    }

    /**
     * 查询用户作业数据
     * @param condition 查询条件
     */
    @RequestMapping("/findUserTaskDataList")
    public List<BigDecimal> findUserTaskDataList(@RequestBody ClassesTaskDataCondition condition){
        return classesTaskDataBiz.findUserTaskDataList(condition);
    }
}
